﻿using ManagedServices.UI.Web.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using ManagedServices.Common.Utility;

namespace ManagedServices.Common.Test
{
    
    
    /// <summary>
    ///This is a test class for SubServiceMetadataModelTest and is intended
    ///to contain all SubServiceMetadataModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SubServiceMetadataModelTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SubServiceMetadataModel Constructor
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void SubServiceMetadataModelSerialzationDeSerializationTest()
        {
            SubServiceMetadataModel target  = new SubServiceMetadataModel();
            target.SubServiceName           = "Test Sub Service";
            target.SubServiceDescription    = "Some Description";
            target.Version                  = "1.0.0.0";
            target.UniqueURN                = "http://managedservices.codeplex.com/schemas/TestSubService";
            target.Dependencies             = new DependencyMetadataModel[4];
            target.Dependencies[0]          = new DependencyMetadataModel { Name = "Test.dll",           DependencyType = "StartupAssembly" };
            target.Dependencies[1]          = new DependencyMetadataModel { Name = "Test2.dll",          DependencyType = "Assembly" };
            target.Dependencies[2]          = new DependencyMetadataModel { Name = "Test.exe.config",    DependencyType = "AppConfig" };
            target.Dependencies[3]          = new DependencyMetadataModel { Name = "Test.settings",      DependencyType = "Settings" };
            target.Parameters               = new ParameterModel[2];
            target.Parameters[0]            = new ParameterModel { ParameterName = "Param1", ParameterType = "String", ParameterDefaultValue = "Test" };
            target.Parameters[1]            = new ParameterModel { ParameterName = "Param2", ParameterType = "String", ParameterDefaultValue = "Test" };
            target.RunConfig                = new RunConfigModel { RunMode = "Automatic", RunConfig = "" };
            target.Subscriptions            = new SubscriptionModel[1];
            target.Subscriptions[0]         = new SubscriptionModel { MessageRootName="TestMessage", MessageNamespace="http://managedservices.codeplex.com/schemas/testmessage" };
            string xmlData                  =   SerializationHelper.XmlSerialize<SubServiceMetadataModel>(target);
            SubServiceMetadataModel deSerialized = SerializationHelper.XmlDeSerialize<SubServiceMetadataModel>(xmlData);
            Assert.AreEqual(target.UniqueURN, deSerialized.UniqueURN);
        }
    }
}
